/**
 * 选择
 * */

export default {
    created() {
        this.handlersSel = null
    },
    methods: {
        onToolSel() {
            this.handlersSel = new Cesium.ScreenSpaceEventHandler(this.$viewer.scene.canvas)
            this.handlersSel.setInputAction(event => {
                var pickedObject = this.$viewer.scene.pick(event.position)
                if (pickedObject && pickedObject.id && pickedObject.id.eventName && pickedObject.id.eventName === 'DrawTool') {
                    // 如果是单entity 如点线面
                    if (pickedObject.id.name && pickedObject.id.name.indexOf('DrawTool') !== -1) {
                        this.$viewer.entities.remove(pickedObject.id)
                        this.entitiesDrawTool.delete(pickedObject.id.name)
                    }
                    // 如果是数据源，如测量 删除整体
                    if (pickedObject.id.dataSourceName) {
                        var ds = this.$viewer.dataSources.getByName(pickedObject.id.dataSourceName)
                        this.$viewer.dataSources.remove(ds[0], true)
                    }
                }
            }, Cesium.ScreenSpaceEventType.LEFT_CLICK)
            this.handlersSel.setInputAction(event => {
                var pickedObject = this.$viewer.scene.pick(event.endPosition)
                if (pickedObject && pickedObject.id && pickedObject.id.eventName && pickedObject.id.eventName === 'DrawTool') {
                    this.$viewer._container.style.cursor = 'pointer'
                } else {
                    this.$viewer._container.style.cursor = 'default'
                }
            }, Cesium.ScreenSpaceEventType.MOUSE_MOVE)
        },
        offToolSel() {
            if (this.handlersSel) {
                this.handlersSel.destroy()
                this.handlersSel = null
            }
        }
    }
}
